; Windows NSIS 安装脚本
; 用于创建 Windows 安装程序

!define APP_NAME "ColorBlockDownloader"
!define APP_VERSION "1.0.0"
!define APP_PUBLISHER "Your Name"
!define APP_URL "https://example.com"
!define APP_EXE "ColorBlockDownloader.exe"

; 安装程序设置
Name "${APP_NAME}"
OutFile "ColorBlockDownloader_Setup.exe"
InstallDir "$PROGRAMFILES\${APP_NAME}"
InstallDirRegKey HKLM "Software\${APP_NAME}" "Install_Dir"
RequestExecutionLevel admin

; 包含现代界面
!include "MUI2.nsh"

; 定义界面页面
!define MUI_ABORTWARNING
!define MUI_ICON "resources\icons\app-icon.ico"
!define MUI_UNICON "resources\icons\app-icon.ico"

; 页面顺序
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "LICENSE"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

; 卸载页面
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

; 语言
!insertmacro MUI_LANGUAGE "SimpChinese"

; 安装部分
Section "Install" SecInstall
  ; 设置输出路径
  SetOutPath "$INSTDIR"
  
  ; 复制所有文件
  File /r "dist\ColorBlockDownloader\*.*"
  
  ; 创建快捷方式
  CreateDirectory "$SMPROGRAMS\${APP_NAME}"
  CreateShortCut "$SMPROGRAMS\${APP_NAME}\${APP_NAME}.lnk" "$INSTDIR\${APP_EXE}"
  CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${APP_EXE}"
  
  ; 写入注册表
  WriteRegStr HKLM "Software\${APP_NAME}" "Install_Dir" "$INSTDIR"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "DisplayName" "${APP_NAME}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "NoRepair" 1
SectionEnd

; 卸载部分
Section "Uninstall" SecUninstall
  ; 删除文件和目录
  RMDir /r "$INSTDIR"
  RMDir /r "$SMPROGRAMS\${APP_NAME}"
  
  ; 删除快捷方式
  Delete "$DESKTOP\${APP_NAME}.lnk"
  
  ; 删除注册表项
  DeleteRegKey HKLM "Software\${APP_NAME}"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
SectionEnd